<template>
  <!-- 登录/退出弹出框-->
  <el-dialog
    :title="titleTxt"
    :visible.sync="open"
    center
    width="1024px"
    :close-on-click-modal="true"
    @close="closeFn"
  >
    <el-form ref="logForm" :model="formData" label-width="126px">
      <el-row type="flex" v-if="confirm">
        <el-col :span="12">
          <el-form-item label="交易流水号" prop="rspId">
            <el-input v-model="formData.rspId" :disabled="true"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="系统编号" prop="sysCode">
            <el-select v-model="formData.sysCode" placeholder="" style="width: 100%" :disabled="true">
              <el-option
                v-for="dict in dictMap.SYS_CODE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请状态" prop="curSysStatus">
            <el-select v-model="formData.curSysStatus" placeholder="" style="width: 100%" :disabled="true">
              <el-option
                v-for="dict in dictMap.LOGINOPERATIONTYPECODE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="24">
          <el-form-item label="备注" prop="remarks" :disabled="false">
            <el-input type="textarea" v-model="formData.remarks" maxlength="256" show-word-limit/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" v-if="showBtn" class="dialog-footer" align="center">
      <el-button icon="el-icon-edit-outline" v-if="dialogType === 0" type="primary" @click="login">登录</el-button>
      <el-button icon="el-icon-edit-outline" v-if="dialogType === 1" type="primary" @click="logout">退出</el-button>
      <el-button icon="el-icon-edit-outline" v-if="dialogType === 2" type="primary" @click="query">查询</el-button>
      <el-button @click="closeFn">关闭</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {login, logout, query} from "@/api/cnaps/ccms/805/login_or_logout_entry.js";

export default {
  name: "logEntryDialog",
  components: {},
  props: {
    dictMap: {
      type: Object,
      default: () => {
        return {};
      },
    },
    formData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    dialogType: {
      type: Number,
      default: 0,
    },
    titleTxt: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      // 是否显示弹出层
      open: false,
      confirm: false,
      showBtn: false,
      currentRow: [],
      opButtonList: () => {
        return [];
      },
    };
  },
  mounted() {
  },
  watch: {
    open(d) {
      if (d) {
        this.confirm = false;
        this.showBtn = true;
      } else {
        this.$emit("editComplete", true);
      }
    },
  },
  methods: {
    // 登录
    login() {
      login(this.formData).then((res) => {
        this.msgSuccess("登录成功！");
        this.formData.rspId = res.result.rspId;
        this.confirm = true;
      });
    },
    // 登出
    logout() {
      logout(this.formData)
        .then((res) => {
          this.formData.rspId = res.result.rspId;
          this.msgSuccess("退出成功！");
          this.confirm = true;
          this.showBtn = false;
        })
        //接口报错 暂时这样写 后续修改
        // *******************************************************//
        .catch((res) => {
          this.confirm = true;
          this.formData.rspId = 111;
          this.showBtn = false;
        });
    },
    // 查询
    query() {
      query(this.formData).then((res) => {
        this.msgSuccess("查询成功！");
        this.formData.rspId = res.result.rspId;
        this.confirm = true;
      });
    },
    // 表单重置
    reset() {
      this.resetForm("logForm");
    },
    closeFn() {
      this.open = false;
    },
    show() {
      this.open = true;
    },
    cancel() {
      this.open = false;
      this.reset();
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
